package kr.ac.ml.action;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import ac.kr.ml.dao.ListDao;
import ac.kr.ml.dao.ReplyDao;
import ac.kr.ml.vo.ContentVo;
import ac.kr.ml.vo.ReplyVo;
import kr.ac.ml.mvc.Action;

public class ReplyListAction extends Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response)
			throws IOException, ServletException {
		// TODO Auto-generated method stub
		
		System.out.println("ReplyListaction");
		
		String content_idStr = request.getParameter("con_id");
		int content_id = Integer.parseInt(content_idStr);
		//리스트가져오기
		
		ReplyDao dao = new ReplyDao();
		List<ReplyVo> list = dao.getList(content_id);
		String jsonStr = "";
		if(list != null){		
			
			int length = list.size();	
			
			jsonStr += "{";
			jsonStr += "\"ReplyList\":[";
			
			for(int i = 0; i < length; i++){
				jsonStr += "{";
				jsonStr += 		"\"re_id\":\"" + list.get(i).getRe_id() + "\",";
				jsonStr += 		"\"content_id\":\"" + list.get(i).getCountent_id() + "\",";
				jsonStr +=		"\"commend\":\"" + list.get(i).getCommend() + "\",";
				jsonStr += 		"\"re_writer\":\"" + list.get(i).getRe_writer() + "\"";
				jsonStr += "}";
				
				if(i < length - 1) jsonStr += ",";
			}
			
			jsonStr += "]";
			jsonStr += "}";
		}

//		
		request.setAttribute("json", jsonStr);

	}

}
